package bubuntux.util;

import java.util.ArrayList;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

public class CommandLine extends ArrayList<String> {

	private static final long serialVersionUID = 3787908187555420L;

	public CommandLine(String cmd) {
		super();
		this.add(cmd);
	}

	public CommandLine(String cmd, String... parameters) {
		this(cmd);
		for (int i = 0; i < parameters.length; i++) {
			this.add(parameters[i]);
		}
	}

	public void cleanParameters() {
		for (int i = 0; i < this.size(); i++) {
			if (StringUtils.isBlank(this.get(i))) {
				this.remove(i);
				i--;
			}
		}
	}

	/**
	 * Returns true if this list contains elements.
	 * 
	 * @return true if this list contains elements
	 */
	public boolean isNotEmpty() {
		return !this.isEmpty();
	}

	@Override
	public String toString() {
		return ArrayUtils.toString(this.toArray());
	}

	public String[] toStringArray() {
		String[] returnCommand = new String[this.size()];
		for (int i = 0; i < returnCommand.length; i++) {
			returnCommand[i] = this.get(i);
		}

		return returnCommand;
	}
}
